//
//  XJAfterSaleTVC1.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/20.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJAfterSaleTVC1.h"
#import "XJAfterSaleHistoryModel.h"
#import "XJAfterSaleHistoryCell.h"


@interface XJAfterSaleTVC1 ()
@property(nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation XJAfterSaleTVC1

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    
    [self requestData];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"XJAfterSaleHistoryCell" bundle:nil] forCellReuseIdentifier:@"XJAfterSaleHistoryCell"];
    self.tableView.tableFooterView = [UIView new];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XJAfterSaleHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XJAfterSaleHistoryCell" forIndexPath:indexPath];
    
    
    cell.model = self.dataArray[indexPath.row];
//    NSLog(@"%@",self.dataArray[indexPath.row]);
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}


#pragma mark - 网路请求
- (void)requestData {
    [XJHttpTool requestRefoundListSuccessH:^(id responseObjc) {
        
        NSString *code = [NSString stringWithFormat:@"%@",responseObjc[@"code"]];
        if ([code isEqualToString:@"0"]) {
            
            NSArray *refund_list = responseObjc[@"data"][@"refund_list"];
            for (NSDictionary *dic in refund_list) {
//                XJAfterSaleHistoryModel *model = [[XJAfterSaleHistoryModel alloc] init];
                
                XJAfterSaleHistoryModel *model = [XJAfterSaleHistoryModel mj_objectWithKeyValues:dic];
                [model setValuesForKeysWithDictionary:dic];
                
                [self.dataArray addObject:model];
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView reloadData];
            });
            
        }else {
            XJLog(@"出错:%@",responseObjc);
        }
        
    } failH:^(NSError *error) {
        [JRToast showWithText:[error localizedDescription]];
    }];
}

@end
